package top.tangyh.lamp.care.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Param;
import top.tangyh.basic.base.mapper.SuperMapper;
import top.tangyh.lamp.care.entity.BPatient;
import org.springframework.stereotype.Repository;
import top.tangyh.lamp.care.vo.result.PatientBedInfoOutVO;
import top.tangyh.lamp.care.vo.result.PatientHomePageOutVO;
import top.tangyh.lamp.care.vo.result.PatientInfoOutVO;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * 病人信息表
 * </p>
 *
 * @author zqb
 * @date 2024-07-12 16:37:12
 * @create [2024-07-12 16:37:12] [zqb] [代码生成器生成]
 */
@Repository
public interface BPatientMapper extends SuperMapper<BPatient> {

    List<PatientInfoOutVO> selectPatientListOfSystemLeftMenu(@Param("deptIdent") String deptIdent);

    List<PatientBedInfoOutVO> selectPatientListOfSystemLeftMenuBed(@Param("deptIdent") String deptIdent, @Param("bedNumber") String bedNumber);

    List<PatientHomePageOutVO> selectListByDeptNew(@Param("deptIdent") String deptIdent);

    default int updateLiYuanStatus(String hospitalNumber,Integer status) {
        LambdaQueryWrapper<BPatient> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BPatient::getHospitalNumber, hospitalNumber);
        BPatient yxPatientPO = new BPatient();
        yxPatientPO.setIsLeave(status);
        return this.update(yxPatientPO, queryWrapper);
    }

    default BPatient selectOneByPatIdent(String patIdent) {
        LambdaQueryWrapper<BPatient> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BPatient::getPatientIdent, patIdent)
                .orderByDesc(BPatient::getCreatedTime)
                .last("limit 1");
        return this.selectOne(queryWrapper);
    }

    default BPatient selectOneByHospitalNumber(String hospitalNumber) {
        LambdaQueryWrapper<BPatient> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BPatient::getHospitalNumber, hospitalNumber)
                .orderByDesc(BPatient::getHisCreatedTime)
                .last("limit 1");
        return this.selectOne(queryWrapper);
    }

    default BPatient selectOneByHospitalNumbers(List<String> hospitalNumbers) {
        LambdaQueryWrapper<BPatient> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(BPatient::getHospitalNumber, hospitalNumbers)
                .orderByDesc(BPatient::getCreatedTime)
                .last("limit 1");
        return this.selectOne(queryWrapper);
    }


    default BPatient selectOneByPatiens(List<String> patients) {
        LambdaQueryWrapper<BPatient> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(BPatient::getPatientIdent, patients)
                .orderByDesc(BPatient::getCreatedTime)
                .last("limit 1");
        return this.selectOne(queryWrapper);
    }


    /**
     * 病人表和入科表关联查询
     *
     * @param deptIdent
     * @return
     */
    List<PatientInfoOutVO> selectListByDept(@Param("deptIdent") String deptIdent);


}


